package cn.com.bluemoon.daps.standard.client;

import cn.com.bluemoon.metadata.inter.RemoteStandardIndexMetaDataService;
import cn.com.bluemoon.metadata.inter.dto.out.StandardIndexAssociatedFineReportVO;
import cn.com.bluemoon.metadata.inter.factory.RemoteStandardIndexMetaDataServiceFallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * @author Jarod.Kong
 */
@Component
@Slf4j
public class RemoteStandardIndexMetaDataServiceFacade {
    @Autowired
    private RemoteStandardIndexMetaDataService remoteStandardIndexMetaDataService;

    @Bean
    public RemoteStandardIndexMetaDataServiceFallbackFactory remoteStandardIndexMetaDataServiceFallbackFactory(){
        return new RemoteStandardIndexMetaDataServiceFallbackFactory();
    }

    public List<StandardIndexAssociatedFineReportVO> standardIndexAssociatedFineReportVOS(String tableName, String fieldName){
        cn.com.bluemoon.metadata.common.ResultBean<List<StandardIndexAssociatedFineReportVO>> res = null;
        try {
            res = remoteStandardIndexMetaDataService.analysisStandardIndexAssociatedFineReport(tableName, fieldName);
        } catch (Exception e) {
            log.error("远程元数据服务调用失败", e);
            return Collections.emptyList();
        }
        return res.getContent();
    }
}
